package com.hospital.vac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hospital.vac.entity.Permission;
import com.hospital.vac.entity.RolePermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
/**
 * @description 权限菜单数据访问层
 * @return
 * @author ANLGIN
 * @since 2023/3/9 17:08
 */

public interface PermissionMapper extends BaseMapper<Permission> {

    /**
    * 通过角色id查询菜单信息
    */
    @Select("select * from role_permission where role_id = #{roleId}")
    List<RolePermission> getRolePermissionByRoleId(Integer roleId);

    /**
    * 根据角色id删除菜单信息
    */
    @Delete("delete from role_permission where role_id = #{roleId}")
    void deletePermissionsByRoleId(Integer roleId);

    /**
    * 插入角色信息和菜单信息
    */
    @Insert("insert into role_permission(role_id, permission_id) values(#{roleId}, #{permissionId})")
    void insertRoleAndPermission(@Param("roleId") Integer roleId, @Param("permissionId") Integer permissionId);

}
